package cn.com.scan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.com.scan.R;
import cn.com.scan.entity.Storage;

/**
 * Created by My on 2016/1/1.
 */
public class StorageAdapter extends BaseAdapter{
    Context context;
    List<Storage> objects;
    public StorageAdapter(Context context,List<Storage> objects) {
        this.context=context;
        this.objects=objects;
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Storage  storage=objects.get(position);
        ViewHolder viewHolder;
        if(convertView==null){
           viewHolder=new  ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.storage_adapter_item,parent,false);
            viewHolder.textView=(TextView)convertView.findViewById(R.id.textView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder)convertView.getTag();
        }
        viewHolder.textView.setText(storage.getSTORAGE_NAME());
        return convertView;
    }
    class ViewHolder{
        TextView textView;
    }
}
